package com.hongyuan.venue.data;

import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.hongyuan.mvvmhabitx.base.BaseModel;
import com.hongyuan.venue.data.http.HttpDataSource;
import com.hongyuan.venue.data.http.MyBaseResponse;
import com.hongyuan.venue.data.sourse.LocalDataSource;
import com.hongyuan.venue.data.userbean.MemberLoginBean;
import com.hongyuan.venue.data.userbean.TokenBean;
import com.hongyuan.venue.ui.home.beans.CouponBean;
import com.hongyuan.venue.ui.home.beans.MemberOsBean;
import com.hongyuan.venue.ui.home.beans.SecheduleBeans;
import com.hongyuan.venue.ui.home.beans.StoreInfoBean;
import com.hongyuan.venue.ui.home.beans.TopTimeBean;
import com.hongyuan.venue.ui.home.beans.TrainBeans;
import com.hongyuan.venue.ui.home.beans.TrainningDetailBeans;
import com.hongyuan.venue.ui.home.beans.Venue;
import com.hongyuan.venue.ui.home.beans.VenuePayBeans;
import com.hongyuan.venue.ui.main.beans.AlipayBean;
import com.hongyuan.venue.ui.main.beans.CheckVersionBeans;
import com.hongyuan.venue.ui.main.beans.NoDataBean;
import com.hongyuan.venue.ui.main.beans.PhoneMessageTokenBean;
import com.hongyuan.venue.ui.main.beans.ReturnImgsBean;
import com.hongyuan.venue.ui.main.beans.ReturnMoreImgBean;
import com.hongyuan.venue.ui.person.beans.CouponHubBean;
import com.hongyuan.venue.ui.person.beans.KeFuBean;
import com.hongyuan.venue.ui.person.beans.MyCouponBeans;
import com.hongyuan.venue.ui.person.beans.MyOrderDeatilBean;
import com.hongyuan.venue.ui.person.beans.MyOrdersBean;
import com.hongyuan.venue.ui.person.beans.PersonBean;
import com.hongyuan.venue.ui.person.beans.TrainningOrdersBean;
import com.hongyuan.venue.ui.site.beans.SiteBeans;
import com.hongyuan.venue.ui.wxapi.WecathPayBean;

import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.RequestBody;

public class MyRepository extends BaseModel implements HttpDataSource, LocalDataSource {

    private volatile static MyRepository INSTANCE = null;

    private final HttpDataSource mHttpDataSource;

    private final LocalDataSource mLocalDataSource;

    private MyRepository(@NonNull HttpDataSource mHttpDataSource, @NonNull LocalDataSource mLocalDataSource){
        this.mHttpDataSource = mHttpDataSource;
        this.mLocalDataSource = mLocalDataSource;
    }

    public static MyRepository getInstance(HttpDataSource mHttpDataSource, LocalDataSource mLocalDataSource){
        if(INSTANCE == null){
            synchronized (MyRepository.class){
                if(INSTANCE == null){
                    INSTANCE = new MyRepository(mHttpDataSource,mLocalDataSource);
                }
            }
        }

        return INSTANCE;
    }

    @VisibleForTesting
    public static void destroyInstance(){
        INSTANCE = null;
    }

    /************************************接口请求操作***********************************************/

    @Override
    public Observable<MyBaseResponse<TokenBean>> api_token(Map<String, String> params) {
        return mHttpDataSource.api_token(params);
    }

    @Override
    public Observable<MyBaseResponse<MemberLoginBean>> memberlogin(Map<String, String> params) {
        return mHttpDataSource.memberlogin(params);
    }

    @Override
    public Observable<MyBaseResponse<ReturnImgsBean>> upfile_oss(Map<String, RequestBody> params) {
        return mHttpDataSource.upfile_oss(params);
    }

    @Override
    public Observable<MyBaseResponse<ReturnMoreImgBean>> upfile_oss_more(Map<String, RequestBody> params) {
        return mHttpDataSource.upfile_oss_more(params);
    }

    @Override
    public Observable<MyBaseResponse<NoDataBean>> send_regi_msg(Map<String, String> params) {
        return mHttpDataSource.send_regi_msg(params);
    }

    @Override
    public Observable<MyBaseResponse<PhoneMessageTokenBean>> get_token(Map<String, String> params) {
        return mHttpDataSource.get_token(params);
    }

    @Override
    public Observable<MyBaseResponse<NoDataBean>> do_find_password(Map<String, String> params) {
        return mHttpDataSource.do_find_password(params);
    }

    @Override
    public Observable<MyBaseResponse<MemberLoginBean>> memberlogin_dxm(Map<String, String> params) {
        return mHttpDataSource.memberlogin_dxm(params);
    }

    @Override
    public Observable<MyBaseResponse<CheckVersionBeans>> check_app_version(Map<String, String> params) {
        return mHttpDataSource.check_app_version(params);
    }

    @Override
    public Observable<MyBaseResponse<MemberOsBean>> get_member_os(Map<String, String> params) {
        return mHttpDataSource.get_member_os(params);
    }

    @Override
    public Observable<MyBaseResponse<StoreInfoBean>> get_offline_store_info(Map<String, String> params) {
        return mHttpDataSource.get_offline_store_info(params);
    }

    @Override
    public Observable<MyBaseResponse<Venue>> gym_detail(Map<String, String> params) {
        return mHttpDataSource.gym_detail(params);
    }

    @Override
    public Observable<MyBaseResponse<NoDataBean>> all_coupon_list_gc(Map<String, String> params) {
        return mHttpDataSource.all_coupon_list_gc(params);
    }

    @Override
    public Observable<MyBaseResponse<TrainBeans>> course_train_list(Map<String, String> params) {
        return mHttpDataSource.course_train_list(params);
    }

    @Override
    public Observable<MyBaseResponse<SiteBeans>> gym_list(Map<String, String> params) {
        return mHttpDataSource.gym_list(params);
    }

    @Override
    public Observable<MyBaseResponse<PersonBean>> get_member_index_info(Map<String, String> params) {
        return mHttpDataSource.get_member_index_info(params);
    }

    @Override
    public Observable<MyBaseResponse<KeFuBean>> get_online_kf(Map<String, String> params) {
        return mHttpDataSource.get_online_kf(params);
    }

    @Override
    public Observable<MyBaseResponse<List<TopTimeBean>>> get_plan_date(Map<String, String> params) {
        return mHttpDataSource.get_plan_date(params);
    }

    @Override
    public Observable<MyBaseResponse<SecheduleBeans>> gym_reserve_list(Map<String, String> params) {
        return mHttpDataSource.gym_reserve_list(params);
    }

    @Override
    public Observable<MyBaseResponse<WecathPayBean>> getPrePayOrder(Map<String, String> params) {
        return mHttpDataSource.getPrePayOrder(params);
    }

    @Override
    public Observable<MyBaseResponse<AlipayBean>> unifiedorder(Map<String, String> params) {
        return mHttpDataSource.unifiedorder(params);
    }

    @Override
    public Observable<MyBaseResponse<MyOrdersBean>> gym_order_list(Map<String, String> params) {
        return mHttpDataSource.gym_order_list(params);
    }

    @Override
    public Observable<MyBaseResponse<NoDataBean>> cancle_order(Map<String, String> params) {
        return mHttpDataSource.cancle_order(params);
    }

    @Override
    public Observable<MyBaseResponse<MyOrderDeatilBean>> get_order_info(Map<String, String> params) {
        return mHttpDataSource.get_order_info(params);
    }

    @Override
    public Observable<MyBaseResponse<VenuePayBeans>> order_gym_mx(Map<String, String> params) {
        return mHttpDataSource.order_gym_mx(params);
    }

    @Override
    public Observable<MyBaseResponse<CouponBean>> use_coupon_list(Map<String, String> params) {
        return mHttpDataSource.use_coupon_list(params);
    }

    @Override
    public Observable<MyBaseResponse<CouponHubBean>> os_coupon_list(Map<String, String> params) {
        return mHttpDataSource.os_coupon_list(params);
    }

    @Override
    public Observable<MyBaseResponse<NoDataBean>> get_coupon(Map<String, String> params) {
        return mHttpDataSource.get_coupon(params);
    }

    @Override
    public Observable<MyBaseResponse<MyCouponBeans>> my_coupon_list(Map<String, String> params) {
        return mHttpDataSource.my_coupon_list(params);
    }

    @Override
    public Observable<MyBaseResponse<NoDataBean>> update_member_head(Map<String, String> params) {
        return mHttpDataSource.update_member_head(params);
    }

    @Override
    public Observable<MyBaseResponse<NoDataBean>> update_member_name(Map<String, String> params) {
        return mHttpDataSource.update_member_name(params);
    }

    @Override
    public Observable<MyBaseResponse<NoDataBean>> update_member_sex(Map<String, String> params) {
        return mHttpDataSource.update_member_sex(params);
    }

    @Override
    public Observable<MyBaseResponse<NoDataBean>> update_member_birth(Map<String, String> params) {
        return mHttpDataSource.update_member_birth(params);
    }

    @Override
    public Observable<MyBaseResponse<NoDataBean>> update_m_info(Map<String, String> params) {
        return mHttpDataSource.update_m_info(params);
    }

    @Override
    public Observable<MyBaseResponse<NoDataBean>> update_member_sign(Map<String, String> params) {
        return mHttpDataSource.update_member_sign(params);
    }

    @Override
    public Observable<MyBaseResponse<TrainningDetailBeans>> course_train_detail(Map<String, String> params) {
        return mHttpDataSource.course_train_detail(params);
    }

    @Override
    public Observable<MyBaseResponse<VenuePayBeans>> order_course_train(Map<String, String> params) {
        return mHttpDataSource.order_course_train(params);
    }

    @Override
    public Observable<MyBaseResponse<TrainningOrdersBean>> course_train_order_list(Map<String, String> params) {
        return mHttpDataSource.course_train_order_list(params);
    }


    /************************************数据存储操作***********************************************/

    @Override
    public void saveToken(TokenBean bean) {
        mLocalDataSource.saveToken(bean);
    }

    @Override
    public TokenBean getToken() {
        return mLocalDataSource.getToken();
    }

    @Override
    public void saveUser(MemberLoginBean bean) {
        mLocalDataSource.saveUser(bean);
    }

    @Override
    public MemberLoginBean getUser() {
        return mLocalDataSource.getUser();
    }
}
